#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

#include<string.h>

int main() {
	char a[100];
	fgets(a, sizeof(a), stdin);
	int min, max, ch1, ch2;
	ch1 = strlen(a);
	min = 0;
	for (int i = 0; i < ch1; i++) {
		if (a[i] < a[min]) {
			min = i;
		}
	}
	char b[100];
	fgets(b, sizeof(b), stdin);
	ch2 = strlen(b);
	max = 0;
	for (int j = 0; j < ch2; j++) {
		if (b[j] > b[max]) {
			max = j;
		}
	}
	printf("%d %d\n", max, min);
	for (int z = ch1; z >= min ; z--) {
		a[z + 1] = a[z];
	}
	puts(a);
	a[min + 1] = b[max];
	printf("\n");
	puts(a);
	return 0;
}